home *** CD-ROM | disk | FTP | other *** search
- #define ShowINIT foo
- #include "Misc.h"
- #undef ShowINIT
-
- void ShowINIT(short iconID, short advance);
-
- #if 0
- ; File: ShowINIT.a
- ; Last Modified: Sunday, November 26, 1989 05:07:56 PM
- ;------------------------------------------------------------------------------------------------
- ;
- ; INIT notification routine
- ; by Paul Mercer, Darin Adler, Paul Snively and Frédéric Miserey from an idea by Steve Capps
- ;
- ; Created: 6/7/87 PM - First version.
- ; Modified: 6/15/87 PM - Changed to standard (Pascal) calling conventions.
- ; 6/20/87 PM - Fixed color & Finder bug on Mac II.
- ; 6/22/87 DBA - Improved handling of QuickDraw.
- ; 6/29/87 DBA - Used scratch8 to avoid conflict with “Easy Access”.
- ; 6/30/87 DBA - Changed to a 4-byte scheme with “checksum”.
- ; 6/30/87 PFS - Separated into ShowINIT and InnerShowINIT.
- ; 7/1/87 DBA - Fixed stack bug and switched to CurApName+.
- ; 7/2/87 PM - Added check for old signature in ApplScratch for
- ; backword compatibility (TMON Startup).
- ; 7/3/87 PM - Removed _SysBeep in ErrorExit since it causes a crash.
- ; Also changed ICN# plotter to srcOr mode for Blinker.
- ; 7/13/87 PM - Fixed a3 trashing bug in InnerShowINIT - exit code left
- ; word on stack (reported by D. Dunham).
- ; 7/21/87 PM - Due to popular demand, InitGraf is no longer being called.
- ; This avoids the gamma correction problem with Startupscreens
- ; getting “washed out” by ShowINIT though someone else is still
- ; bound to call InitGraf sooner or later (i.e. InitWindows).
- ; 7/29/87 PM - Put InitGraf back in; this is required (reported by C. Derossi
- ; at Apple Tech Support). Took out GetPort/SetPort.
- ; 10/06/87 PM - Set CurrentA5 properly. Rearranged myVars.
- ; 12/28/87 PM - Major revision to accomodate future INIT31 based ShowINIT.
- ; 07/14/88 PM - Major revision to get rid of above 'accomodations'.
- ; Added color icon 'cicn' support and fixed beep crash.
- ; Removed support for old signature.
- ; 11/25/89 FCM - Added Y dimension support, icl48 support to get rid of 'obsolete' cicns
- ; 8/28/90 jbx - Translated to Think C, added automatic x-movement determination.
- ; 6/22/92 jbx - Cleaned up slightly from internal Now version for MacHack use.
- ; Also cleaned up interface to DrawAnIcon routine.
- ;------------------------------------------------------------------------------------------------
- #endif
-
- /* Originally written by Paul Mercer. Translated to Think C by jbx. The latest ShowINIT
- source is always up on AppleLink, so if there's a version there later than 11/25/89,
- the version that added vertical wrap support, you should examine it for changes. */
-
- typedef struct {
- long Icon[32];
- long IconMask[32];
- } ICONList, *ICONListPtr, **ICONListHdl;
-
- extern short myVCheck : 0x928; /* a GREAT place to store 8 bytes (it was Darin's idea) */
- extern short myV : 0x92A;
- extern short myH : 0x92C;
- extern short myHCheck : 0x92E; /* a simple checksum of myH to determine first-timeness */
-
- enum {
- firstX = 8, /* X coordinate of first icon to be drawn */
- bottomEdge = 8+32, /* this far from bottom of screen */
- iconWidth = 32, /* size of icon (square normally) */
- defaultMoveX = 40, /* x default amount to move icons */
- defaultMoveY = 40, /* y icon line height */
- checksumConst = 0x1021, /* constant used for computing checksum */
-
- iconRowBytes = 32/8, /* 32/8 bits */
-
- hasCQDBit = 6 /* this bit in ROM85 is cleared if Color QuickDraw is available */
-
- };
-
- struct {
- char qd_privates[76]; /* known only to Apple and MacWEEK... */
- long qd_randSeed;
- BitMap qd_screenBits;
- Cursor qd_arrow;
- Pattern qd_dkGray;
- Pattern qd_ltGray;
- Pattern qd_gray;
- Pattern qd_black;
- Pattern qd_white;
- GrafPtr qd_thePort;
- } myqd;
-
- #define thePort myqd.qd_thePort
- #define white myqd.qd_white
- #define black myqd.qd_black
- #define gray myqd.qd_gray
- #define ltGray myqd.qd_ltGray
- #define dkGray myqd.qd_dkGray
- #define arrow myqd.qd_arrow
- #define screenBits myqd.qd_screenBits
- #define randSeed myqd.qd_randSeed
-
- static long saveA5;
- static long localA5;
-
- static Rect srcRect = {0,0,32,32}; /* for copybits */
- static Rect destRect= {0,0,32,32};
-
- static BitMap myBitMap = {
- 0, /* address */
- iconRowBytes, /* rowBytes */
- 0,0,32,32 /* Rect */
- };
- static BitMap myMaskMap = {
- 0, /* address */
- iconRowBytes, /* rowBytes */
- 0,0,32,32 /* Rect */
- };
- static GrafPort myPort;
-
- static short Advance;
-
- static Rect Zero32 = {0, 0, 32, 32};
-
- void DrawAnIcon(void *BlackAndWhiteIcon, void *ColorIcon, short iclDepth, Rect dstRect) {
- ICONListPtr iconPtr = BlackAndWhiteIcon;
- PixMapHandle pmh;
- PixMapPtr pmp;
- void *oldA4 = SetA4(&main);
-
- myBitMap.baseAddr = (void *)iconPtr->Icon;
- myBitMap.bounds = Zero32;
- myMaskMap.baseAddr = (void *)iconPtr->IconMask;
- myMaskMap.bounds = Zero32;
-
- if (!ColorIcon || !(pmh = NewPixMap())) {
- CopyMask(&myBitMap, &myMaskMap, &theQDPort()->portBits, &Zero32, &Zero32, &dstRect);
- } else {
- HLock(pmh);
- pmp = *pmh;
- DisposHandle(pmp->pmTable);
- pmp->pmTable = (CTabHandle) RGetResource('clut', iclDepth);
- pmp->baseAddr = ColorIcon;
- pmp->rowBytes = 0x8000 | (iclDepth * iconRowBytes);
- pmp->bounds = srcRect;
- pmp->pixelType = chunky;
- pmp->pixelSize = iclDepth;
- pmp->cmpCount = 1;
- pmp->cmpSize = iclDepth;
-
- CopyMask(pmp, &myMaskMap, &theQDPort()->portBits, &Zero32, &Zero32, &dstRect);
-
- pmp->pmTable = (void *)NewHandle(0);
- DisposPixMap(pmh);
- }
-
- SetA4(oldA4);
- }
-
- static void ShowINITCredits(void) {
- asm {
- dc.b "ShowINIT by Paul Mercer" ,0
- dc.b "Copyright 1987-1989" ,0
- dc.b "Version of 11/25/89" ,0
- dc.b "Modified by jbx 6/9/92" ,0
- };
- }
-
- /***************************************************************************************\
- | |
- | Initializes the world and sets up the drawing rectangle |
- | |
- \***************************************************************************************/
-
- static void INITInit(void) {
- asm {
- move.l CurrentA5,saveA5 ; PM 10/6 save host A5
- lea localA5,a5 ; PM7/21
- move.l a5,CurrentA5
- pea thePort ; PM 10/6 use a5 reference instead of a6
- InitGraf ; fixes color bug as per DA@ICOM
- pea myPort
- OpenPort
-
- move.w myV,d0 ; get my v var
- rol.w #1,d0 ; compare against checksum
- eor.w #checksumConst,d0
- cmp.w myVCheck,d0
- beq.s @ScratchVOK ; checks, so go on test my h var
-
- move.w myPort.portBits.bounds.bottom,d0 ; else initialize as first time
- sub.w #bottomEdge,d0
- move d0,myV
- ScratchVOK:
- move.w myH,d0 ; get my h var
- rol.w #1,d0 ; compare against checksum
- eor.w #checksumConst,d0
- cmp.w myHCheck,d0
- beq.s @ScratchHOK ; checks, so go on
- move #firstX,myH ; else initialize as first time
- ScratchHOK:
- move.l myV,d0 ; trickery - high word is V, lo word is H.
-
- move.w d0,d1 ; get future position
- add.w #iconWidth,d1 ; compute future rect right
- cmp.w myPort.portBits.bounds.right,d1 ; compare to main screen right
- blt.s @DontChangeLine ; smaller - do nothing
-
- move.w myV,d0 ; decrement Y value
- subi.w #defaultMoveY,d0
- move.w d0,myV
- move.w #firstX,myH ; set X to initial value
-
- move.l myV,d0
- DontChangeLine:
- lea destRect,a0
- move.l d0,(a0)+
- move.l d0,(a0)
- }
- }
-
- /***************************************************************************************\
- | |
- | Advances the icon drawing position and adjusts destRect |
- | |
- \***************************************************************************************/
-
- static void MaskAdjust(void) {
- short ht, wd;
-
- destRect.bottom += (ht = myMaskMap.bounds.bottom - myMaskMap.bounds.top);
- destRect.right += (wd = myMaskMap.bounds.right - myMaskMap.bounds.left);
-
- if (Advance) {
- myH += wd + 8;
- }
- }
-
- /***************************************************************************************\
- | |
- | Cleans up the work done by INITInit and advances the icon drawing position |
- | |
- \***************************************************************************************/
-
- static void INITCleanup(void) {
- asm {
- move.w myH,d0 ; get current position
- rol.w #1,d0 ; recompute h checksum
- eor.w #checksumConst,d0
- move.w d0,myHCheck ; and save it
-
- move myV,d0 ; same for v checksum
- rol.w #1,d0
- eor.w #checksumConst,d0
- move.w d0,myVCheck
-
- pea myPort ; *** (DBA) I think that QuickDraw leaves handles around.
- ClosePort ; *** (DBA) Too bad we can't get rid of them...
-
- move.l saveA5,a5 ; PM 10/6 restore host A5
- move.l a5,CurrentA5
- }
- }
-
- /***************************************************************************************\
- | |
- | Displays the ICN# (cicn when in 4 bit mode or higher) specified by iconID. |
- | |
- | PROCEDURE ShowINIT(iconID: Integer); EXTERNAL; |
- | |
- | pascal void ShowINIT(short iconID); |
- | extern; |
- | |
- \***************************************************************************************/
-
- // jbx change: addec "advance" parameter for animating icons. Call ShowINIT(ID) to
- // show an icon, and call ShowINIT(0, ID) to show it but not advance the drawing
- // position so that the next time you call ShowINIT it will draw over the one you
- // just drew. If you're wondering why the advance parameter is done this way, it's
- // to keep compatibility with old code that just calls ShowINIT(-4064) etc.
-
- void ShowINIT(short iconID, short advance) {
- ICONListHdl BWicon;
- Handle icon;
- long depth;
-
- short oldmyH = myH;
- short oldmyHC = myHCheck;
-
- void *oldA4 = SetA4(&main);
-
- INITInit(); /* initialize for drawing */
-
- Advance = 1;
- if (iconID == 0) {
- iconID = advance;
- Advance = 0;
- }
-
- // always try to get the black and white icon
- BWicon = (void *)GetResource('ICN#', iconID); // try to get the icon resource.
- if (ROM85 <= 0x3FFF) { // try to get a color icon if CQD exists
- depth = (**(**GetMainDevice()).gdPMap).pixelSize;
- if (depth >= 4) {
- if (BWicon) {
- if (depth > 8) depth = 8; // depth is either 4 or 8 now.
- icon = GetResource('icl0' + depth, iconID);
- if (!icon) {
- depth = (4 + 8) - depth;
- icon = GetResource('icl0' + depth, iconID);
- }
- if (icon) {
- HLock(icon);
- HLock(BWicon);
- myMaskMap.baseAddr = (void *)(**BWicon).IconMask;
- MaskAdjust();
-
- DrawAnIcon(*BWicon, *icon, depth, destRect);
- ReleaseResource(icon);
- ReleaseResource(BWicon);
- goto success;
- }
- }
-
- // OK, try for a cicn.
- if (icon = (void *)GetCIcon(iconID)) {
- myMaskMap = ((CIconHandle)icon)[0]->iconMask;
- myMaskMap.baseAddr = (void *)((CIconHandle)icon)[0]->iconMaskData;
- MaskAdjust();
- PlotCIcon(&destRect, icon);
- DisposCIcon(icon);
- goto success;
- }
- }
- }
-
- // OK, try to use a black and white icon.
- if (BWicon) {
- HLock(BWicon);
- myBitMap.baseAddr = (void *)(**BWicon).Icon;
- myMaskMap.baseAddr = (void *)(**BWicon).IconMask;
-
- MaskAdjust();
-
- CopyMask(&myBitMap, &myMaskMap, &myPort.portBits, &srcRect, &srcRect, &destRect);
- ReleaseResource(BWicon);
- goto success;
- }
-
- success:
- INITCleanup();
- SetA4(oldA4);
- }